<template>
	<a-select show-search :filter-option="filterOption" placeholder="请选择用户" v-model:value="selectedValue">
		<a-select-option v-for="option in userList" :key="option.id" :value="getOptionValue(option)" :label="option.name">
			{{ option.name }}
		</a-select-option>
	</a-select>
</template>

<script setup>
	import { ref, defineProps } from 'vue'
	import userApi from '@/api/biz/bizUserApi'

	const props = defineProps({
		valueField: {
			type: String,
			default: 'id' // 默认使用id字段
		}
	})

	const userList = ref([])
	const selectedValue = ref(null)

	const getOptionValue = (option) => {
		return props.valueField === 'account' ? option.account : option.id
	}

	const filterOption = (input, option) => {
		return option.label.toLowerCase().includes(input.toLowerCase())
	}

	onMounted(() => {
		userApi.listAllUser().then((res) => {
			userList.value = res
		})
	})
</script>
